

<!DOCTYPE html>
<html>

<head>


    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <!--360浏览器优先以webkit内核解析-->


    <title>费用申请明细</title>
    <script src="__STATIC__/layout/js/jquery.min.js"></script>
    <link rel="shortcut icon" href="__STATIC__/layout/favicon.ico">
    <link href="__STATIC__/layout/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <script src="__STATIC__/layout/js/bootstrap.min.js?v=3.3.6"></script>
    <link href="__STATIC__/layout/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="__STATIC__/layout/css/animate.css" rel="stylesheet">
    <!--<link href="__STATIC__/layout/css/style.css?v=4.1.0" rel="stylesheet">-->
    <link href="__STATIC__/layout/css/channel.css?v=4.1.0" rel="stylesheet">
    <!-- Sweet Alert -->
    <link href="__STATIC__/layout/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <script src="__STATIC__/layout/js/plugins/suggest/bootstrap-suggest.min.js"></script>
    <!--<link href="__STATIC__/layout/js/plugins/select/bootstrap-select.css" rel="stylesheet">-->
    <link rel="stylesheet" href="__STATIC__/layout/css/demo.css" type="text/css">
    <link href="__STATIC__/layout/css/gyq.css" rel="stylesheet">
    <link href="__STATIC__/xds/js/select2/css/select2.css" rel="stylesheet" />
    <script src="__STATIC__/xds/js/select2/js/select2.js"></script>
    <script src="__STATIC__/layout/js/jquery.cookie.js?"></script>

    <style>
        .hover{
            display: block;
            width: 80px;
            line-height: 30px;
            height: 30px;
            overflow: hidden;
            position: relative;
        }
        .hover:hover{
            overflow: visible;
        }
        .hover .ex{
            position: absolute;
            left: 80px;
            top: 0;
            width: 200px;
            line-height: 60px;
            background: #ff0;
            text-align: center;
        }
    </style>

    <style>
        #form1 p{
            line-height: 20px;
            padding: 4px;
        }
        .titleImg{
            width: 20px;
            height: 20px;
            margin-right: 8px;
            display: inline-block;
            vertical-align: middle;
        }
        .table{
            margin-bottom: 10px;
        }
        .handup{
            color: #a6e1fc;
            display: inline-block;
            padding-left: 10px;
            cursor: pointer;
        }
        .btn-white.active{
            color: #fff;
            background-color: #337ab7;
        }
        .bootstrap-select{
            height: 36px;
            border-radius: 6px;
        }
        .bootstrap-select .btn-default {
            border-radius: 6px;
            background-color: #fff;
            border-color: #c2c2c2;
            color: #333;
        }
        .btn-default:hover, .btn-default:focus, .btn-default:active, .btn-default.active, .open .dropdown-toggle.btn-default{
            border-radius: 6px;
            background-color: #fff;
            border-color: #c2c2c2;
            color: #333;
        }
    </style>

</head>

<body class="white-bg" style="padding: 3px;font-size: 13px">
<div class="page-heade">
    <h2 class="title_color text-center">费用申请明细</h2>
</div>
<form action="" class="form-inline" id="form1">
    <input type="hidden" name="tiapplyid" id="tiapplyid" {if condition="$aid neq 0"} value="{$aid}" {/if}/>
    <!--新加的-->
    <input name="zon" id="zon" value="{$title}" type="hidden"/>
    <input name="ti_id" id="ti_id" value="{$id}" type="hidden"/>
    <input name="jxs_id" value="{$jxsid}" id="jxs_ids" type="hidden"/>

    <input name="khxqtype" id="khxqtype" value="2" type="hidden"/>
    <input name="cpxqtype" id="cpxqtype" value="1" type="hidden"/>

    <input name="fylx" id="fylx" value="" type="hidden"/>
    <p><img  class="titleImg" src="__STATIC__/layout/img/activityXiTong.png" alt=""><b>基本信息 {$fylx}</b></p>
    <input type="hidden" id="fylxs"  name="fylxs" value="{$fylx}">
    <!--基本信息-->
    <table class="table table-bordered bud_hei">
        <thead>
        <tr class="info">
            <th class="text-center">活动期间</th>
            <th class="text-center">预算期间</th>
            <th class="text-center">预计核销日期</th>
            <th class="text-center">活动简述及目的</th>
            <th class="text-center">所属专项方案</th>
        </tr>
        </thead>
        <tbody>
        <tr class="text-center">
            <td>
                        <span class="xds_addTime"  whereTime="startName:s1,endName:s2,jisuanshijiancha:#actionText,GetDateStr:#yujihexiaotime,disabled:1,rets:'活动期间必须选择'" >
                        </span>
                <span class="text-danger"  id="actionText"></span>
            </td>
            <td class="xds_addTime"  whereTime="startName:start,endName:end,disabled:1,rets:'预算期间必须选择'" >
            </td>
            <td><input type="text" id="yujihexiaotime"  name="expCanTime" class="form-control"></td>
            <td><input type="text" id="hdjs" class="form-control" name="brief" style="width: 95%"></td>
            <td>无</td>
        </tr>
        </tbody>
    </table>
    <p><img  class="titleImg" src="__STATIC__/layout/img/activityXiTong.png" alt=""><b>费用详情</b></p>
    <table class="table table-bordered bud_hei">
        <thead>
        <tr class="info">
            <th class="text-center">费用类型</th>
            <th class="text-center">支付方式</th>
            <th class="text-center">费用额（含税）</th>
            <th class="text-center">收款方</th>
            <th class="text-center">成本中心</th>
            <th class="text-center">费用说明</th>
            <th class="text-center">
                <button class="btn btn-success " type="button" id="FeiYongLeiXingAn" onclick="addHang()" >
                    <i class="fa fa-plus-square"></i>&nbsp;&nbsp;
                    <span class="bold" >添加</span>
                </button>
            </th>
        </tr>
        </thead>
        <tbody id="FeiYongLeiXingList">

        </tbody>
    </table>
    <p style=""><img  class="titleImg" src="__STATIC__/layout/img/activityXiTong.png" alt=""><b>客户详情</b>&nbsp;&nbsp;&nbsp;

    <div   id="is_kehuxiangqing">

    </div>

    </p>
    <table class="table table-bordered bud_hei" id="angencyTable" style="display: none;">
        <tr>
            <td><b>{$titlename}</b></td>
        </tr>
    </table>
    <table class="table table-bordered bud_hei" id="netTable" style="display: none;">
        <tr>
            <td style="min-width: 180px;width: 180px" class="text-right"><label for="" >网点<span class="colorRed">*</span>：</label></td>
            <td colspan="3">
                <div class="col-xs-4">
                    <div class="input-group" id="" >
                        <input type="text"   placeholder="请输入关键字或空格查询" class="form-control inputremindPeple" id="net"  value="{:isset($supply)?$supply.jxs:''}">
                        <input type="hidden" name="nets" id="nets"/>
                        <div class="input-group-btn">
                            <ul class="dropdown-menu dropdown-menu-right" role="menu">
                            </ul>
                        </div>
                    </div>
                </div>
                <div class="col-xs-4">
                    <button class="btn btn-primary btn-sm" id="select_net">选择</button>
                    <input type="button" class="btn btn-primary btn-sm" id="clear_net" value="清空"/>
                    <a href="javascript:;" id="select_my_net">选择我的常用网点分组</a>
                </div>
            </td>
        </tr>
        <tr>
            <td style="min-width: 180px;width: 180px" class="text-right"><label for="" >您选定的网点是：</label></td>
            <td class="text-left" colspan="3">
                <div class="duoxuan" id="selected_net">
                    {if isset($list)}
                    {volist name="list.net" id="row"}
                    <span class="ren" data-id="{$row.id}">{$row.title}<span class="close">×</span></span>
                    {/volist}
                    {/if}
                </div>
            </td>
        </tr>
        <!--<tr>
            <td>
                 <div class="input-group form-group" id="WangDian" style="display: inline-block;" >

                </div>
                &lt;!&ndash;<select class="selectpicker show-menu-arrow" id="WangDianmultiples" style="width:100% ">
                </select>&ndash;&gt;

            </td>
        </tr>-->
    </table>
    <table class="table table-bordered bud_hei" id="sysTable" >
        <thead>
        <tr class="info">
            <th class="text-center">系统</th>
            <th class="text-center">费用占比</th>
            <th class="text-center">预计投放网点数</th>
            <th class="text-center">
                <button class="btn btn-success " type="button" onclick="addHang2()"><i class="fa fa-plus-square"></i>&nbsp;&nbsp;<span class="bold">添加</span>
                </button>
            </th>
        </tr>
        </thead>
        <tbody   id="JinXiaoShangZhu">

        </tbody>
    </table>
    <p><img  class="titleImg" src="__STATIC__/layout/img/activityXiTong.png" alt=""><b>产品详情</b>&nbsp;&nbsp;&nbsp;
    <div id="is_changpingxiangqin">

    </div>

    <i id="proText">注：产品费用占比加起来必须等于100%,如果不填费用占比则平摊</i>
    </p>

    <table class="table table-bordered bud_hei"   id="proTable0">
        <thead>
        <tr class="info">
            <th class="text-center">产品</th>
            <th class="text-center">费用占比</th>
            <th class="text-center">产品说明</th>
            <th class="text-center">
                <button class="btn btn-success " type="button" onclick="addHang3()">
                    <i class="fa fa-plus-square"></i>&nbsp;&nbsp;<span class="bold">添加</span>
                </button></th>
        </tr>
        </thead>
        <tbody id="Cpxq0">

        </tbody>
    </table>
    <table class="table table-bordered bud_hei"  style="display: none;" id="proTable1">
        <thead>
        <tr class="info">
            <th class="text-center">产品</th>
            <th class="text-center">费用占比</th>
            <th class="text-center">产品说明</th>
            <th class="text-center"> <button class="btn btn-success " type="button" onclick="addHang4()"><i class="fa fa-plus-square"></i>&nbsp;&nbsp;<span class="bold">添加</span>
            </button></th>
        </tr>
        </thead>
        <tbody id="Cpxq1">

        </tbody>
    </table>
    <table class="table table-bordered bud_hei"  style="display: none;" id="proTable2">
        <thead>
        <tr class="info">
            <th class="text-center">产品</th>
            <th class="text-center">费用占比</th>
            <th class="text-center">产品说明</th>
            <th class="text-center"> <button class="btn btn-success " type="button" onclick="addHang5()"><i class="fa fa-plus-square"></i>&nbsp;&nbsp;<span class="bold">添加</span>
            </button></th>
        </tr>
        </thead>
        <tbody id="Cpxq2">

        </tbody>
    </table>
    <table class="table table-bordered bud_hei"  style="display: none;" id="proTable3">
        <thead>
        <tr class="info">
            <th class="text-center">产品</th>
            <th class="text-center">费用占比</th>
            <th class="text-center">产品说明</th>
            <th class="text-center">
                <button class="btn btn-success " type="button" onclick="addHang6()">
                    <i class="fa fa-plus-square"></i>&nbsp;&nbsp;<span class="bold">添加</span>
                </button>
            </th>
        </tr>
        </thead>
        <tbody id="Cpxq3">

        </tbody>
    </table>
    <table class="table table-bordered bud_hei" id="proTable4" style="display: none;">
        <thead>
        <tr class="info">
            <th class="text-center">产品</th>
            <th class="text-center">产品说明</th>
            <th class="text-center">
                <button class="btn btn-success " type="button" onclick="addHang7()"><i class="fa fa-plus-square"></i>&nbsp;&nbsp;<span class="bold">添加</span>
                </button>
            </th>
        </tr>
        </thead>
        <tbody id="Cpxq4">

        </tbody>
    </table>
    <!--/ 随货折扣类单品/-->
    <table class="table table-bordered bud_hei" id="proTable42" style="display: none;">
        <thead>
        <tr class="info">
            <th class="text-center">产品</th>
            <th class="text-center">数量</th>
            <th class="text-center">经销商特价</th>
            <th class="text-center">产品说明</th>
            <th class="text-center">
                <button class="btn btn-success " type="button" onclick="addHang72()"><i class="fa fa-plus-square"></i>&nbsp;&nbsp;<span class="bold">添加</span>
                </button>
            </th>
        </tr>
        </thead>
        <tbody id="Cpxq42">

        </tbody>
    </table>

    <!--/ 产品进场类/-->
    <table class="table table-bordered bud_hei" id="proTable43" style="display: none;">
        <thead>
        <tr class="info">
            <th class="text-center">产品</th>
            <th class="text-center">零售商供货价</th>
            <th class="text-center">卖场零售价</th>
            <th class="text-center">产品说明</th>
            <th class="text-center">
                <button class="btn btn-success " type="button" onclick="addHang73()"><i class="fa fa-plus-square"></i>&nbsp;&nbsp;<span class="bold">添加</span>
                </button>
            </th>
        </tr>
        </thead>
        <tbody id="Cpxq43">

        </tbody>
    </table>

    <!--/ 特价补差类/-->
    <table class="table table-bordered bud_hei" id="proTable44" style="display: none;">
        <thead>
        <tr class="info">
            <th class="text-center">产品</th>
            <th class="text-center">数量</th>
            <th class="text-center">经销商特价</th>
            <th class="text-center">系统/网点特价</th>
            <th class="text-center">零售价</th>
            <th class="text-center">产品说明</th>
            <th class="text-center">
                <button class="btn btn-success " type="button" onclick="addHang74()"><i class="fa fa-plus-square"></i>&nbsp;&nbsp;<span class="bold">添加</span>
                </button>
            </th>
        </tr>

        </thead>
        <tbody id="Cpxq44">

        </tbody>
    </table>


    <p>
        <img  class="titleImg" src="__STATIC__/layout/img/activityXiTong.png" alt="">
        <b>销量预测</b>&nbsp;&nbsp;&nbsp;
    <div id="is_shejixiaoliang">
    </div>

    </p>
    <table class="table table-bordered bud_hei" id="sallycTable">
        <thead>
        <tr class="info">
            <th class="text-center">预计销售类型</th>
            <th class="text-center">不做活动销售额</th>
            <th class="text-center">做活动销售额</th>
            <th class="text-center">增量销售额</th>
            <th class="text-center">申请费用额合计</th>
            <th class="text-center">预计费用率</th>
        </tr>
        </thead>
        <tbody>
        <tr class="text-center">
            <td>
                <select name="yjSalesType" id="yjSalesType" class="form-control" style="height: 30px;">
                    <option value="0">请选择</option>
                    <option value="1">经销商进货</option>
                    <option value="2">经销商出货</option>
                    <option value="3">网点零售</option>
                </select>
            </td>
            <td>
                <div class="input-group">
                    <input type="text" id="noSales" name="noSales" onchange="Saleschange()" class="form-control" aria-label="RMB" style="width: 60px;height: 30px" >
                    <span class="input-group-addon">元</span>
                </div>
            </td>
            <td>
                <div class="input-group">
                    <input type="text" id="yesSales" name="yesSales" onchange="Saleschange()" class="form-control"  aria-label="RMB" style="width: 60px;height: 30px" >
                    <span class="input-group-addon">元</span>
                </div>
            </td>
            <td id="addSales"></td>
            <td class="text-right" name="sqfy" id="sqfy">2321.3元</td>
            <input  type="hidden" name="sqfy"  id="sqfys" >
            <td class="text-right"  id="yjfyl" ></td>
            <input  type="hidden" name="yjfyl"  id="yjfyls" >
        </tr>
        </tbody>
    </table>
    <input type="button" id="baocunadd"  class="btn btn-success" value="保存并再添加一条2">
    <input type="button" id="baocunret" class="btn btn-success" value="保存并并返回">

    <input type="button" class="btn btn-warning" value="返回" id="fanhui">


</form>
<!-- 全局js -->

<script src="__STATIC__/layout/js/contabs_sub.js"></script>

<!-- Sweet alert -->
<script src="__STATIC__/layout/js/plugins/sweetalert/sweetalert.min.js"></script>
<script src="__STATIC__/layout/js/plugins/laydate/laydate.js"></script>

<!--<script type="text/javascript" src="__STATIC__/layout/js/plugins/select/bootstrap-select.js"></script> -->
<!-- Chosen -->
<script src="__STATIC__/layout/js/plugins/chosen/chosen.jquery.js"></script>
<script src="__STATIC__/layout/js/plugins/layer/layer.min.js"></script>

<script src="__STATIC__/xds/js/time.js"></script>
<script src="__STATIC__/xds/js/select.js"></script>
<script src="__STATIC__/xds/js/tifeiyong.js"></script>
<script src="__STATIC__/xds/js/addTr.js"></script>
<script type="text/javascript">var jisuanurl="{:url('Bs/tejia')}";</script>
<script src="__STATIC__/xds/js/jisuan.js"></script>
<script>

    function baocunadd(){
        console.log('aaa');
        ifInputNull('#baocunadd',function () {
            console.log('1');
            var res=tijiaoyanzheng();
            console.log(res);
            console.log('2');
            if(res["stauts"]==1){
                $.ajax({
                    // cache: false,
                    type: "POST",
                    url:"{:url('TiFeiyong/addapply')}",
                    //data:parent.$('#zhuapply').serialize(),// 你的formid
                    data:$('#form1').serialize(),// 你的formid
                    async: false,
                    /*error: function(request) {
                        alert("Connection error");
                    },*/
                    success: function(data) {
                        var res1=JSON.parse(data);
                        if(res1["state"]==1){
                            swal({
                                title: "完成",
                                text: "操作已成功",
                                type: "success"
                            },function(){
                                /*parent.window.location="{:url('TiApply/addform')}?aid="+$("#tiapplyid").val();
                                parent.layer.close(parent.layer.getFrameIndex(window.name))*/
                                parent.window.location="{:url('TiApply/addform')}?aid="+$("#tiapplyid").val();
                                parent.layer.close(parent.layer.getFrameIndex(window.name))

                                // parent.window.location="{:url('TiFeiyong/addinfohtml')}?aid="+$("#ti_id").val();
                                //parent.layer.close(parent.layer.getFrameIndex(window.name))
                                //location.href="{:url('TiApply/addlisthtml')}?aid="+"{$id}"+"&jxs={$jxsid}"+"id="+"{$id}";
                                //parent.window.location="{:url('TiFeiyong/addlisthtml')}?aid="+"{$id}"+"&jxs={$jxsid}"+"id="+"{$id}";


                                /*var index = layer.open({
                                    type: 2,
                                    title: '添加费用明细',
                                    area: ['90%', '90%'],
                                    fixed: false, //不固定
                                    maxmin: true,
                                    /!*btn:["保存","返回"],*!/
                                    content:"{:url('TiFeiyong/addListHtml')}?id="+"{$id}"+"&jxs={$jxsid}"+'&aid='+"{$id}"
//                           content:"{:url('TiFeiyong/addListHtml')}?id="+data.value.id+'&jxsid='+testNoBtn
                                });
                                layer.full(index)*/

                                /*// location.href="{:url('TiFeiyong/addinfohtml')}?aid="+$("#tiapplyid").val();
                                location.href="{:url('TiFeiyong/addinfohtml')}?aid="+$("#ti_id").val();*/
                            });

                        }else{
                            swal({
                                title: "错误",
                                text:  res1["msg"],
                                type: "warning"
                            });
                        }
                    }

                });

                //baocun()
            }else if(res["stauts"]==2){

                swal('',res["msg"],'warning');
                return false;

                /*swal({
                    title: "错误",
                    text:  res["msg"],
                    type: "warning"
                });*/
            }

        });
        /*if($("#tiapplyid").val()==""){
            console.log('aaa')
            //没有申请
            $.ajax({
                cache: true,
                type: "POST",
                url:"{:url('TiApply/addapply')}",
                data:parent.$('#form1').serialize(),// 你的formid
                async: false,
                error: function(request) {
                    alert("Connection error");
                },
                success: function(data) {
                    var res1=JSON.parse(datas);
                    if(res1["state"]==1){
                        swal({
                            title: "完成",
                            text: "操作已成功",
                            type: "success"
                        },function(){
                            //location.href="{:url('TiFeiyong/addinfohtml')}?aid="+$("#tiapplyid").val();
                            location.href="{:url('TiFeiyong/addinfohtml')}?aid="+$("#ti_id").val();
                        });

                    }else{
                        swal({
                            title: "错误",
                            text:  res1["msg"],
                            type: "warning"
                        });
                    }
                }
            });
        }else{
            //有申请
            $.ajax({
                cache: true,
                type: "POST",
                url:"{:url('TiApply/addapplydetail')}",
                data:$('#f1').serialize(),// 你的formid
                async: false,
                error: function(requests) {
                    alert("Connection error");
                },
                success: function(datas) {
                    var res1=JSON.parse(datas);
                    if(res1["state"]==1){
                        swal({
                            title: "完成",
                            text: "操作已成功",
                            type: "success"
                        },function(){

                            location.href="{:url('TiApply/addData')}?aid="+$("#tiapplyid").val();
                        });

                    }else{
                        swal({
                            title: "错误",
                            text:  res1["msg"],
                            type: "warning"
                        });
                    }
                }
            });
        }*/
    }
    //
    //保存返回
    function baocun(){
        if($("#tiapplyid").val()==""){
            //没有申请
            $.ajax({
                cache: true,
                type: "POST",
                url:"{:url('TiApply/addapply')}",
                data:parent.$('#zhuapply').serialize(),// 你的formid
                async: false,
                error: function(request) {
                    alert("Connection error");
                },
                success: function(data) {
                    //alert(data);
                    var res=JSON.parse(data);
                    $("#tiapplyid").val(res["aid"]);
                    $.ajax({
                        cache: true,
                        type: "POST",
                        url:"{:url('TiApply/addapplydetail')}",
                        data:$('#f1').serialize(),// 你的formid
                        async: false,
                        error: function(requests) {
                            alert("Connection error");
                        },
                        success: function(datas) {
                            //alert(datas);
                            var res1=JSON.parse(datas);
                            if(res1["state"]==1){
                                swal({
                                    title: "完成",
                                    text: "操作已成功",
                                    type: "success"
                                },function(){
                                    parent.window.location="{:url('TiApply/addform')}?aid="+$("#tiapplyid").val();
                                    parent.layer.close(parent.layer.getFrameIndex(window.name))
                                });

                            }else{
                                swal({
                                    title: "错误",
                                    text:  res1["msg"],
                                    type: "warning"
                                });
                            }
                        }
                    });
                }
            });
        }else{
            //有申请
            $.ajax({
                cache: true,
                type: "POST",
                url:"{:url('TiApply/addapplydetail')}",
                data:$('#f1').serialize(),// 你的formid
                async: false,
                error: function(requests) {
                    alert("Connection error");
                },
                success: function(datas) {
                    //alert(datas);
                    var res1=JSON.parse(datas);
                    if(res1["state"]==1){
                        swal({
                            title: "完成",
                            text: "操作已成功",
                            type: "success"
                        },function(){
                            parent.window.location="{:url('TiApply/addform')}?aid="+$("#tiapplyid").val();
                            parent.layer.close(parent.layer.getFrameIndex(window.name))
                        });

                    }else{
                        swal({
                            title: "错误",
                            text:  res1["msg"],
                            type: "warning"
                        });
                    }
                }
            });
        }
    }

    //保存并添加
    $("#baocunadd").click(function(){
        console.log('www');
        ifInputNull('#baocunadd',function () {
            console.log('1');
            var res=tijiaoyanzheng();
            console.log(res);
            console.log('2');
            if(res["stauts"]==1){
                $.ajax({
                    // cache: false,
                    type: "POST",
                    url:"{:url('TiFeiyong/addapply')}",
                    //data:parent.$('#zhuapply').serialize(),// 你的formid
                    data:$('#form1').serialize(),// 你的formid
                    async: false,
                    /*error: function(request) {
                        alert("Connection error");
                    },*/
                    success: function(data) {
                        var res1=JSON.parse(data);
                        if(res1["state"]==1){
                            swal({
                                title: "完成2",
                                text: "操作已成功",
                                type: "success"
                            },function(){
                                /*parent.window.location="{:url('TiApply/addform')}?aid="+$("#tiapplyid").val();
                                parent.layer.close(parent.layer.getFrameIndex(window.name))*/


                                parent.window.location="{:url('TiFeiyong/addinfohtml')}?aid="+$("#ti_id").val();
                                parent.layer.close(parent.layer.getFrameIndex(window.name))
                                //  parent.window.location="{:url('TiFeiyong/addlisthtml')}?aid="+"{$id}"+"&jxs={$jxsid}"+"id="+"{$id}";

                                //var testNoBtn = $("input[name='jxs_id']").val();
                                /*layer.open({
                                    type: 2,
                                    title: '添加费用3明细',
                                    area: ['90%', '90%'],
                                    fixed: false, //不固定
                                    maxmin: true,
                                    /!*btn:["保存","返回"],*!/
                                    content:"{:url('TiFeiyong/addListHtml')}?id="+"{$id}"+'&jxsid='+"{$jxsid}"+'&aid='+"{$id}"
//                           content:"{:url('TiFeiyong/addListHtml')}?id="+data.value.id+'&jxsid='+testNoBtn
                                });*/
                                var index = layer.open({
                                    type: 2,
                                    title: '添加费用明细',
                                    area: ['90%', '90%'],
                                    fixed: false, //不固定
                                    maxmin: true,
                                    content:"{:url('TiFeiyong/addListHtml')}?id="+"{$id}"+"&jxs="+"{$jxsid}"+'&aid='+"{$id}"
                                });
                                layer.full(index)
                                //location.href="{:url('TiApply/addlisthtml')}?aid="+"{$id}"+"&jxs={$jxsid}"+"id="+"{$id}";

                                /*// location.href="{:url('TiFeiyong/addinfohtml')}?aid="+$("#tiapplyid").val();
                                location.href="{:url('TiFeiyong/addinfohtml')}?aid="+$("#ti_id").val();*/
                            });

                        }else{
                            swal({
                                title: "错误",
                                text:  res1["msg"],
                                type: "warning"
                            });
                        }
                    }
                });
            }else if(res["stauts"]==2){
                swal('',res["msg"],'warning');
                return false;
            }

        });

    })

    //保存返回
    $("#baocunret").click(function(){
//        console.log('www');
        ifInputNull('#baocunadd',function () {
//            console.log('1');
            var res=tijiaoyanzheng();
//            console.log(res);
//            console.log('2');
            if(res["stauts"]==1){
                $.ajax({
                    // cache: false,
                    type: "POST",
                    url:"{:url('TiFeiyong/addapply')}",
                    //data:parent.$('#zhuapply').serialize(),// 你的formid
                    data:$('#form1').serialize(),// 你的formid
                    async: false,
                    /*error: function(request) {
                        alert("Connection error");
                    },*/
                    success: function(data) {
                        var res1=JSON.parse(data);
                        if(res1["state"]==1){
                            swal({
                                title: "完成",
                                text: "操作已成功",
                                type: "success"
                            },function(){
                                /*parent.window.location="{:url('TiApply/addform')}?aid="+$("#tiapplyid").val();
                                parent.layer.close(parent.layer.getFrameIndex(window.name))*/


                                parent.window.location="{:url('TiFeiyong/addinfohtml')}?aid="+$("#ti_id").val();
                                parent.layer.close(parent.layer.getFrameIndex(window.name))


                                /*// location.href="{:url('TiFeiyong/addinfohtml')}?aid="+$("#tiapplyid").val();
                                location.href="{:url('TiFeiyong/addinfohtml')}?aid="+$("#ti_id").val();*/
                            });

                        }else{
                            swal({
                                title: "错误",
                                text:  res1["msg"],
                                type: "warning"
                            });
                        }
                    }

                });

                //baocun()
            }else if(res["stauts"]==2){

                swal('',res["msg"],'warning');
                return false;

                /*swal({
                    title: "错误",
                    text:  res["msg"],
                    type: "warning"
                });*/
            }

        });
    })

    //返回
    $('#fanhui').click(function () {
        parent.window.location="{:url('TiFeiyong/addinfohtml')}?aid="+$("#ti_id").val();

        /*if($("#tiapplyid").val()!="")
            //parent.window.location="{:url('TiFeiyong/addinfohtml')}?aid="+$("#tiapplyid").val();
        parent.window.location="{:url('TiFeiyong/addinfohtml')}";
        else
            parent.layer.close(parent.layer.getFrameIndex(window.name))*/
    })

    function tijiaoyanzheng(){
        $(".num2").each(function(){
            if(isNaN(parseFloat($(this).val()))){
                $(this).val("0.00");
            }else{
                $(this).val(parseFloat($(this).val()).toFixed(2));
            }
        })
        //验证网点
        var message=[];
        var netarr=[];
        var num=0;
        $(".netlist").each(function(){
            netarr.push($(this).attr("data-id"));

        })
        $("#nets").val(netarr.join(','));
        //产品
        var proarr=[];
        $(".prolist").each(function(){
            proarr.push($(this).attr("data-id"));
        })
        $("#pros").val(proarr.join(','));
        if($("#yujihexiaotime").val()==""){
            message["msg"]="预计核销日期必须填写";message["stauts"]=2;
            return message;
        }
        if($("#hdjs").val()==""){
            message["msg"]="活动简述及目的必须填写";message["stauts"]=2;
            return message;
        }

        if($("#start").val()==""){
            message["msg"]="促销开始时间必须填写";message["stauts"]=2;
            return message;
        }
        if($("#end").val()==""){
            message["msg"]="促销结束时间必须填写";message["stauts"]=2;
            return message;
        }
        console.log('f');
        /*if($("#nets").val()==""){
            message["msg"]="至少选择一个网点";message["stauts"]=2;
            return message;
        }*/
        if($("#pros").val()==""){
            message["msg"]="至少选择一个产品";message["stauts"]=2;
            return message;
        }
        console.log('1');
        //费用记录不能为空
        var ck=1;
        $(".feetype").each(function(){
            num++;
            if($(this).val()==""){
                ck=0;
            }
        })
        if(ck==0){
            message["msg"]="费用名称必须填写";message["stauts"]=2;
            return message;
        }
        ck=1;
        $(".zonge").each(function(){
            if($(this).val()==""||$(this).val()=="0"){
                ck=0;
            }
        })
        if(ck==0){
            message["msg"]="未税总额必须填写并且不能为0";message["stauts"]=2;
            return message;
        }
        ck=1;
        $(".paymethod").each(function(){
            if($(this).val()==0){
                ck=0;
            }
        })
        if(ck==0){
            message["msg"]="支付方式必须选择";message["stauts"]=2;
            return message;
        }
        ck=1;
        $(".jrbm[name='jrbm']").each(function(){
            if($(this).val()==""){
                ck=0;
            }
        })
        if(ck==0){
            message["msg"]="费用计入部门必须选择";message["stauts"]=2;
            return message;
        }
        ck=1;
        $(".project").each(function(){
            if($(this).val()=="0"){
                ck=0;
            }
        })
        if(ck==0){
            message["msg"]="费用计入方案必须选择";message["stauts"]=2;
            return message;
        }
        //至少一项费用num统计次数
        var zongji=0;
        $(".zonge").each(function(){
            if(isNaN(parseFloat($(this).val()))){
                zongji+=0;
            }else{
                zongji+=parseFloat($(this).val());
            }
        })
        zongji+=parseFloat($("#sumjian").val());
        if(zongji==0){
            message["msg"]="至少有一项费用且费用不能为0";message["stauts"]=2;
            return message;
        }
        ///验证产品项
        //预计销量
        ck=1;
        $(".boxs").each(function(){
            if(parseFloat($(this).val())==0){
                ck=0;
            }
        })
        if(ck==0){
            message["msg"]="预计销量不能为0";message["stauts"]=2;
            return message;
        }
        //现经销商价不能为空xianjsx
        ck=1;
        $(".xianjsx").each(function(){
            if(isNaN(parseFloat($(this).val()))){
                ck=0;return false;
            }else{
                if(parseFloat($(this).val())==0){
                    ck=0;return false;
                }
            }
        })
        if(ck==0){
            message["msg"]="经销商现供货价不能为空";message["stauts"]=2;
            return message;
        }
        //网点原供货价
        ck=1;
        $(".netyuan").each(function(){
            if(isNaN(parseFloat($(this).val()))){
                ck=0;return false;
            }else{
                if(parseFloat($(this).val())==0){
                    ck=0;return false;
                }
            }
        })
        if(ck==0){
            message["msg"]="网点原供货价不能为空";message["stauts"]=2;
            return message;
        }
        //网点现
        ck=1;
        $(".xiannet").each(function(){
            if(isNaN(parseFloat($(this).val()))){
                ck=0;return false;
            }else{
                if(parseFloat($(this).val())==0){
                    ck=0;return false;
                }
            }
        })
        if(ck==0){
            message["msg"]="网点现供货价不能为空";message["stauts"]=2;
            return message;
        }
        //原零售价
        ck=1;
        $(".yuanp").each(function(){
            if(isNaN(parseFloat($(this).val()))){
                ck=0;return false;
            }else{
                if(parseFloat($(this).val())==0){
                    ck=0;return false;
                }
            }
        })
        if(ck==0){
            message["msg"]="原零售价不能为空";message["stauts"]=2;
            return message;
        }
        //现零售价
        ck=1;
        $(".xianp").each(function(){
            if(isNaN(parseFloat($(this).val()))){
                ck=0;return false;
            }else{
                if(parseFloat($(this).val())==0){
                    ck=0;return false;
                }
            }
        })
        if(ck==0){
            message["msg"]="促销零售价不能为空";message["stauts"]=2;
            return message;
        }
        ck=0;
        /*$.ajax({
            type: "POST",
            url: "{:url('heduijizhun')}",
            data: {net:$("#nets").val(),pro:$("#pros").val(),start:$("#start").val(),end:$("#end").val()},
            async:false,//注意添加async：false 同步参数
            success:function(re){
                // alert(re);
                if(re==1){
                    ck=1;
                }
            }

        })*/
        /*if(ck==0){
            message["msg"]="";message["stauts"]=3;
            return message;
        }*/
        /*var flag=netfanwei();
        if(flag==1){
            message["msg"]="";message["stauts"]=4;
            return message;
        }*/

        message["msg"]="";message["stauts"]=1;
        return message;
    }

    $(function () {
        $('body').on('click','input[type=text]',function () {
            this.select()
        })
    })


    //弹出选择网点框

    //弹出选择网点框
    $('#select_net').on('click',function () {
        var index = layer.getFrameIndex(window.name)
        layer.open({
            type:2,
            area:['60%','60%'],
            maxmin:true,
            content:'{:url("selectNet")}?index='+index+'&keyword={$jxsid}'
        })
        return  false
    })

    $(document).on("click",".netlist .close",function(){
        $(this).parent().remove();
    })

    $("#clear_net").click(function(){
        $(".netlist").remove();
    })


    /*$(document).on("click","#select_net",function(){
        var index = layer.getFrameIndex(window.name)
        layer.open({
            type:2,
            area:['60%','60%'],
            maxmin:true,
            content:'{:url("selectNet")}?index='+index+'&keyword={jid}'
        })
        return  false
    })*/


    $(document).on("click","input[name=options]",function(){
        $(this).parent('label').siblings().removeClass('active')
        $(this).parent('label').addClass('active')
    })

    //费用类型
    // 样品物料
    function mu(type,id) {
        console.log('ypwltj');
        if(type==1){  //如果type==1，即method=1，会有添加样品物料页面
            $('#myModal1'+id).modal('show');
            $('#xgcbzx'+id).show();
        }
    }
    function gradeChange(id){
        console.log('gradeChange')
        //alert(id);
        //console.log(id);
        var k = 'state'+id;
        //console.log(k);
        var type = $("#"+k).find("option:selected").attr("grade");
        //console.log(type);
        //console.log('eee');
        //alert(type);
        if(type==1){
            $('#myModal1'+id).modal('show');
            $('#xgcbzx'+id).show();
        }else {
            //$('#myModal1'+id).modal('show');
            $('#xgcbzx'+id).hide();
        }
    }

    function tijiao(id) {
        var l = '';
        var m = 0;
        var sum = 0;
        $('.divTid'+id).each(function () {
            console.log($(this).find('.inpbai').val());
            sum += Number($(this).find('.inpbai').val());
        });
        console.log(id)
        console.log('id')

        console.log(sum)
        console.log('sum')
        if(sum!=100){m =2;};
        $('.divTid'+id).each(function () {

            if($(this).find('.inpbai').val()==''||$(this).find('.inpbai').val()==0){

                var z =  $(this).find('.uiName').text();

                if(l==''){
                    l += z;
                }else {
                    l += ','+ z;
                }
                m = 1;
            }

        });
        if(m==1){
            swal('',l+'，请填写占比！','warning');
        }else if(m==2){
            swal('','占比加起来必须等于100%！','warning');
        }else {
            alert('提交成功');
            $("#myModal"+id).modal('hide');

            var str2= '';
            var str3= '';
            $('.divTid'+id).each(function () {
                var uiName=$(this).find('.uiName').text();
                var  tid = $(this).find('.uiName').siblings('input').attr('tid');
                var inpbai=$(this).find('.inpbai').val()
                str2 += '<p class="psClassName" psid="'+tid+'" psTo="'+inpbai+'"><span>'+uiName+'</span>,'+inpbai+'%</p>'
                if(str3==''){
                    str3 = uiName+','+inpbai+'%';
                }else {
                    str3 +=';'+ uiName+','+inpbai+'%';
                }
            });
            str2 = str2+'<input name="cbzx'+id+'" value="'+str3+'" type="hidden"/>';

            $("#showSelectText"+id).html(str2);
        }
    }
    function tijiao2(id) {
        //货补清单 提交后把数据提交到页面
//ywTable
        console.log(id);
        var data="";
        ifInputNull('#YpWl',function () {
            console.log('w');
            var formData = $('#YpWlform'+id).serialize();
            console.log(formData);
            console.log('x');
        })
        $.ajax({
            // cache: false,
            type: "POST",
            url:"{:url('TiFeiyong/deal_hb')}",
//                data:$('#form1').serialize(),// 你的formid
            data:$('#YpWlform'+id).serialize(),
            async: false,
            success: function(data) {
                console.log(data)
                var res1=JSON.parse(data);
                console.log('wert')
                console.log(res1)
                if(res1["state"]==1){
                    $("#myModal1"+id).modal('hide');
                    $("#fRmb"+id).val(res1['sum']);
                    $("#hbxx"+id).val(res1['info']);
                    var yjall=0;
                    $(".fRmb").each(function(){
                        var fRmb =$(this).val();
                        yjall=Number(yjall)+Number(fRmb);
                    })
                    $("#sqfy").text(yjall);

                }else{
                    swal({
                        title: "错误",
                        text:  '数据不完整，请完善！',
                        type: "warning"
                    });
                }
            }

        });

        console.log('y');
        var YpWl='YpWl'+id;
        $("#"+YpWl+">tr").each(function(){

            var units = $(this).children('td').find('.units').text();
            var factorys = $(this).children('td').find('.factorys').text();

            var units2 = $(this).children('td').children('').find('.units').text();
            var factorys2 = $(this).children('td').children('').find('.factorys').text();

            if(units){
                if(data==''){
                    data+='unit:'+units;
                }else {
                    data+="||"+'unit:'+units;
                }
            }


        });
        /*console.log('u');
        console.log(data);
        console.log('y');*/

    }

    function wlnum_to(id){

        var wlnum=$('#wlnum'+id).val();
        if(wlnum!=''){
            var factory = $('#factory'+id).text();
            console.log(factory)
            var all = wlnum * factory;
            console.log(all)
            $('#allmoney'+id).text(all);
            $('#allmoneys'+id).val(all);
        }else{
        }
    }
    function del_this(obj,id) {
        console.log(obj.parent().parent().siblings());
        if(obj.parent().parent().siblings().length<1){

            alert("至少保留一行")
        }else{

            $(id).remove();

        }

    }
    function setSelect(id){
        var strtext = $('#multiples'+id).select2('data');
        var a=[];
        for(var i=0;i<strtext.length;i++){
            a[strtext[i].id] = strtext[i].text;

        }
        var b=[];
        $("#selectDiv"+id+" .divTid").each(function(){
            b[$(this).attr('tid')]=$(this).find('.inpbai').val();
        })
        var str = '' ;
        o = 0;
        for(key in a){
            o++;
            if(b.hasOwnProperty(key)){
                str += '<div class="padding-10 divTid'+id+'" tid="'+key+'">'+
                    '<div class="form-group"><input class="tid" type="hidden" value="'+key+'"/>'+o+'.<span class="uiName">'+a[key]+'</span></div>'+
                    '<div class="form-group" style="float: right;">'+
                    '<div class="input-group">'+
                    '<input type="text" class="form-control inpbai" aria-label="%" style="width: 60px;height: 30px" value="'+b[key]+'" >'+
                    '<span class="input-group-addon">%</span>'+
                    '</div>'+
                    '</div>'+
                    '</div>';
            }else{
                str += '<div class="padding-10 divTid'+id+'" tid="'+key+'">'+
                    '<div class="form-group"><input class="tid" value="'+key+'" style="display: none"/>'+o+'.<span class="uiName">'+a[key]+'</span></div>'+
                    '<div class="form-group" style="float: right;">'+
                    '<div class="input-group">'+
                    '<input type="text" class="form-control inpbai" aria-label="%" style="width: 60px;height: 30px" value="" >'+
                    '<span class="input-group-addon">%</span>'+
                    '</div>'+
                    '</div>'+
                    '</div>';
            }
        }

        $("#selectDiv"+id).html(str);
    }
    function h(id) {
        entranceX2x('wlName'+id,
            "{:url('select/materialjson')}?id="+0,
            '',function (data) {
                console.log('wlName1')
                $(this).val(data.id);
                $(this).closest('.input-group').hide();

                $(this).closest('.input-group').hide();
                $('#select'+id).show().find('.inin').html(data.key);

                var rs = $('#thisWL'+id).attr('rs');
                rs = JSON.parse(rs);

                for(var i=0;i<rs.length;i++){
                    if(rs[i].id==data.id){
                        console.log('wlyp1111')

                        $('.unit'+id).html(rs[i].unit)
                        $('.factory'+id).html(rs[i].factory)
                    }
                }
            }

        );

        entranceX2x('wlName2'+id,
            "{:url('select/materialjson')}?id="+1,
            '',function (data) {
                console.log('wlyp5555')
                $(this).val(data.id);
                $(this).closest('.input-group').hide();

                $(this).closest('.input-group').hide();
                $('#select'+id).show().find('.inin').html(data.key);
                var rs = $('#thisWL'+id).attr('rs2');
                rs = JSON.parse(rs);

                for(var i=0;i<rs.length;i++){
                    if(rs[i].id==data.id){
                        console.log('wlyp2222')
                        $('.unit'+id).html(rs[i].unit)
                        $('.factory'+id).html(rs[i].factory)
                    }
                }
            },2
        );
    }
    function a(id) {
        var al = 'feetype'+id;
        var s2 =  '{:url("BiHaiChaoSheng/selectList",["url"=>"Tifykm","where"=>"$fylxs"])}?str='+al;
//s2是弹出框的url
        entranceX('feetype'+id,
            "{:url('BiHaiChaoSheng/AjaxFYKU2',['fylx'=>$fylx,'channeltypes'=>$channeltype])}",
            s2,
            '',function () {
                if($("input[name=feetype"+id+"]").val()==''){
                    $('#isNull'+id).nextAll().remove();
                }
                else {  //
                    var FeiYonglxVal = $("input[name=feetype"+id+"]").val();
                    var FeiYonglxUrl = "{:url('BiHaiChaoSheng/get3KmDyfkfs')}?id="+FeiYonglxVal; //选择费用类型
                    $.ajax({
                        url: FeiYonglxUrl,
                        type: 'get',
                        dataType: 'json',
                        success: function(data) {
                            if(data.code==200){
                                checkfee()
                                var zi = '';
                                var value = data.value;
                                for (var i =0;i<value.length;i++){
                                    //console.log('ypwl'+i);  //method
                                    $("#state"+id)
                                    zi+='<option method="'+value[i].method+'" grade="'+value[i].method+'" onclick="mu('+value[i].method+','+id+')"  value="'+value[i].id+'">'+value[i].title+'</option>';
                                }   // onclick="mu( 未点击事件，当选择时弹出
                                $('#isNull'+id).after(zi);
                                $('#xgcbzx'+id).on('click',function () {
                                    $('#myModal1'+id).modal('show');
                                });


                                if(data.chenlie==1){
                                    //如果陈列方式是1，则在费用说明中显示陈列方式
                                    $('#cl_type'+id).show();
                                    $('#cl_place'+id).show();
                                    $('#cl_size'+id).show();
                                    //alert('qq');
                                }else{
                                    //如果陈列方式是0，则在费用说明中隐藏陈列方式
                                    $('#cl_type'+id).hide();
                                    $('#cl_place'+id).hide();
                                    $('#cl_size'+id).hide();
                                }

                                $('#addyw'+id).on('click',function () {
                                    $('#myModal1'+id).modal('show');
                                });

                                $("#addyw"+id).click(function(){   //添加样品物料
                                    var date= Date.parse(new Date());
                                    uploadTr(yangpingwuliao,'#YpWl'+id,'',h);
                                })

                                // 随货折扣类  if(data.chenlie==1){
                                //var fylx ="{$fylx}";
                                var fylx =data.fylx;
                                if(fylx==2){
                                    var fylxnum=$('#fylx').val();
                                    $('#fylx').val('2');
                                    //选定经销商
                                    $(".khjinxiaoshnag").parent('label').siblings('label').removeClass('active')
                                    $(".khjinxiaoshnag").parent('label').addClass('active')
                                    $("#angencyTable").show();
                                    $("#sysTable").hide();
                                    $("#netTable").hide();
                                    $(".netlist").remove();
                                    $("#JinXiaoShangZhu").empty();
                                    $("#khxqtype").val('1');
                                    $(".khxitong").attr('disabled',true);
                                    $(".khwangdian").attr('disabled',true);

                                    //选择单品  cpxqdp
                                    $(".cpxqdp").parent('label').siblings('label').removeClass('active')
                                    $(".cpxqdp").parent('label').siblings('label').find('input').attr('disabled',true);
                                    $(".cpxqdp").parent('label').addClass('active')
                                    $(".cpxqdp").attr('disabled',true);//当前单品也不许点击
                                    showTable($(this),42);
                                    $("#Cpxq0").empty();
                                    $("#Cpxq1").empty();
                                    $("#Cpxq2").empty();
                                    $("#Cpxq3").empty();
                                    $("#Cpxq4").empty();

                                    if(fylxnum!=7){
                                        addHang72();
                                    }
                                    $("#cpxqtype").val('5');
                                }else if(fylx==7){  //产品进场类
                                    var fylxnum=$('#fylx').val();
                                    $('#fylx').val('7');
                                    //console.log('fylx==7')
                                    $(".khjinxiaoshnag").attr('disabled',true);//经销商不许点击  khjinxiaoshnag
                                    //选定系统（保留系统、网点，禁止经销商）
                                    //选择单品  cpxqdp
                                    $(".cpxqdp").parent('label').siblings('label').removeClass('active')
                                    $(".cpxqdp").parent('label').siblings('label').find('input').attr('disabled',true);
                                    $(".cpxqdp").parent('label').addClass('active')
                                    $(".cpxqdp").attr('disabled',true);//当前单品也不许点击
                                    showTable($(this),43);
                                    $("#Cpxq0").empty();
                                    $("#Cpxq1").empty();
                                    $("#Cpxq2").empty();
                                    $("#Cpxq3").empty();
                                    $("#Cpxq4").empty();
                                    //addHang72();//需要注释
                                    if(fylxnum!=7){
                                        addHang73();
                                    }
                                    $("#cpxqtype").val('5');
                                }else if(fylx==4){
                                    var fylxnum=$('#fylx').val();
                                    $('#fylx').val('4');
                                    $(".khjinxiaoshnag").attr('disabled',true);//经销商不许点击  khjinxiaoshnag
                                    //选定系统（保留系统、网点，禁止经销商）
                                    //选择单品  cpxqdp
                                    $(".cpxqdp").parent('label').siblings('label').removeClass('active')
                                    $(".cpxqdp").parent('label').siblings('label').find('input').attr('disabled',true);
                                    $(".cpxqdp").parent('label').addClass('active')
                                    $(".cpxqdp").attr('disabled',true);//当前单品也不许点击
                                    showTable($(this),44);
                                    $("#Cpxq0").empty();
                                    $("#Cpxq1").empty();
                                    $("#Cpxq2").empty();
                                    $("#Cpxq3").empty();
                                    $("#Cpxq4").empty();


                                    if(fylxnum!=7){
                                        addHang74();
                                    }
                                    $("#cpxqtype").val('5');


                                }

                            }
                        }
                    });

                }

            });
        $('#is_shoukuanF'+id).AddRadioX(
            [
                {
                    title:'经销商',
                    name:'is_jinxiao',
                    className:'jinxiao',
                    isTrue:false,
                    value:1,
                    fun:function (obj) {
                        $(obj).click(function(){
                            $(this).parent('label').siblings().removeClass('active');
                            $(this).parent('label').addClass('active');
//                                $('input[name=payee'+id+']').val('{$jxsid}');
                            $('input[name=payee'+id+']').val('-1');//当值为-1时，选取的为经销商，并且经销商的值通过jxs_id获取
                            $("#payee"+id).hide();

                        });
                    }
                },
                {
                    title:'供应商',
                    name:'is_gonghuo',
                    className:'gonghuo',
                    isTrue:true,
                    value:0,
                    fun:function (obj) {
                        $(obj).click(function(){
                            $(this).parent('label').siblings().removeClass('active')
                            $(this).parent('label').addClass('active');
                            closeX('payee'+id);
                            $("#payee"+id).show();
                        })

                    }
                }

            ]
        );
        entranceX2('payee'+id,
            "{:url('BiHaiChaoSheng/getGYS')}",
            '');
        entranceX2('cl_type'+id,
            "{:url('BiHaiChaoSheng/AjaxCL',['type'=>1])}",
            '','','陈列类型');
        entranceX2('cl_place'+id,
            "{:url('BiHaiChaoSheng/AjaxCL',['type'=>2])}",
            '','','陈列位置');
        entranceX2('cl_size'+id,
            "{:url('BiHaiChaoSheng/AjaxCL',['type'=>3])}",
            '','','陈列尺寸');

        $("#multiples"+id).select2({
            ajax: {
                /*url: "{:url('BiHaiChaoSheng/ajaxJXSALL')}",*/
                url: "{:url('BiHaiChaoSheng/ajaxZoningALL')}",
                dataType: 'json',
                data: function (params) {
                    console.log('ee')
                    console.log(params)
                    console.log('rr')
                    var query = { //请求的参数, 关键字和搜索条件之类的
                        search: params.term //select搜索框里面的value
                    }
                    console.log(query)
                    // Query paramters will be ?search=[term]&page=[page]
                    return query;
                },
                delay: 1500,
                processResults: function (data, params) {
                    //返回的选项必须处理成以下格式
                    //var results =  [{ id: 0, text: 'enhancement' }, { id: 1, text: 'bug' }, { id: 2, text: 'duplicate' }, { id: 3, text: 'invalid' }, { id: 4, text: 'wontfix' }];
                    var results = data;
                    return {
                        results: results  //必须赋值给results并且必须返回一个obj
                    };
                }

            },
            allowClear: true,
            multiple: true
        }).on("change",function(){
            setSelect(id);

        });

        $("#WangDianmultiples").select2({
            ajax: {
                /*url: "{:url('BiHaiChaoSheng/ajaxJXSALL')}",*/
                /*url: "{:url('BiHaiChaoSheng/ajaxZoningALL')}",*/
                url: "{:url('BiHaiChaoSheng/ajaxNetALL')}",
                dataType: 'json',
                data: function (params) {
                    console.log('ee')
                    console.log(params)
                    console.log('rr')
                    var query = { //请求的参数, 关键字和搜索条件之类的
                        search: params.term //select搜索框里面的value
                    }
                    console.log(query)
                    // Query paramters will be ?search=[term]&page=[page]
                    return query;
                },
                delay: 1500,
                processResults: function (data, params) {
                    //返回的选项必须处理成以下格式
                    //var results =  [{ id: 0, text: 'enhancement' }, { id: 1, text: 'bug' }, { id: 2, text: 'duplicate' }, { id: 3, text: 'invalid' }, { id: 4, text: 'wontfix' }];
                    var results = data;
                    return {
                        results: results  //必须赋值给results并且必须返回一个obj
                    };
                }

            },
            allowClear: true,
            multiple: true
        }).on("change",function(){
            setSelect(id);
        });
        $("#multiples"+id).val([10001,10003]).trigger('change');
        setSelect(id);

    }
    function mu(type,id) {
        if(type==1){  //如果type==1，即method=1，会有添加样品物料页面
            $('#myModal1'+id).modal('show');
            $('#xgcbzx'+id).show();
        }
    }

    var title="{$title}";
    //uploadTr(feiyongxiagqing,'#FeiYongLeiXingList','',a);//把选中的经销商对应到成本中心中
    uploadTr(feiyongxiagqing,'#FeiYongLeiXingList','',a,title);//把选中的经销商对应到成本中心中
    //在新更新的成本中心更改为所选的活动经销商

    /*添加一行*/
    function addHang(){
        uploadTr(feiyongxiagqing,'#FeiYongLeiXingList','',a,title); // 参数title是新增的字段只为更改成本中心
    }
    //客户详情
    //系统
    function b(id) {
        /*entranceX('JinXiaoShang'+id,
            "{:url('BiHaiChaoSheng/AjaxJXS',['jxs'=>$channeltype])}",
            '{:url("BiHaiChaoSheng/selectList",["url"=>"Tixt","where"=>"jxs_$channeltype"])}?str=JinXiaoShang'+id,
            '',
            '');*/
        /*entranceX('JinXiaoShang'+id,
            "{:url('BiHaiChaoSheng/AjaxJXS',['jxs'=>$jxsid])}", // 'jxs'=>$jxsid] 通过所选的活动经销商
            '{:url("BiHaiChaoSheng/selectList",["url"=>"Tixt","where"=>"jxs_$jxsid"])}?str=JinXiaoShang'+id,
            '',
            '');*/

        /*entranceX('JinXiaoShang'+id,
            "{:url('BiHaiChaoSheng/AjaxJXS',['jxs'=>$jxsid])}",  //// 'jxs'=>$jxsid] 通过所选的活动经销商
            '{:url("BiHaiChaoSheng/selectList",["url"=>"Tixt","where"=>"jxs_$jxsid"])}?str=JinXiaoShang'+id,
            '',
            '');*/


        entranceX0('JinXiaoShang'+id,
            "{:url('BiHaiChaoSheng/AjaxJXS',['jxs'=>$jxsid])}",  //// 'jxs'=>$jxsid] 通过所选的活动经销商
            '{:url("BiHaiChaoSheng/selectList",["url"=>"Tixt","where"=>"jxs_$jxsid"])}?str=JinXiaoShang'+id,
            '',
            '');

    }
    uploadTr(kehuxiaongqingXitong,'#JinXiaoShangZhu','',b)
    function addHang2(){
        uploadTr(kehuxiaongqingXitong,'#JinXiaoShangZhu','',b)
    }
    // 网点
    entranceX('WangDian',
        "{:url('BiHaiChaoSheng/AjaxWD',['jxs'=>$jxsid])}",  //// 'jxs'=>$jxsid] 通过所选的活动经销商
        '{:url("BiHaiChaoSheng/selectList",["str"=>"WangDian","url"=>"Tiwd","where"=>"jxs_$jxsid"])}',
        '',
        '');

    //产品网点搜索自动补全
    $("#net").bsSuggest({
        url: "{:url('netjson2')}?jid="+{$jxsid},
        /*effectiveFields: ["userName", "shortAccount"],
         searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias:{title: "名称"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onSetSelectValue', function (e, keyword, data) {
        console.log('eee')
        $(this).val('')
        var bool = false
        $('#selected_net .ren').each(function (idx,o) {
            if($(this).data('id') == keyword.id){
                bool = true;
            }
        })
        if(bool == false){
            $('#selected_net').append('<span class="ren netlist" data-id="'+keyword.id+'">'+keyword.key+'<span class="close">×</span></span>')
        }
    });

    //样品搜索补全
    $(".sample").bsSuggest({
        url: "{:url('select/samplejson')}",
        effectiveFieldsAlias: {title: "名称"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onSetSelectValue', function (e, keyword, data) {
        console.log(keyword,'yp')
        $(this).closest('.input-group').hide()
        $(this).val('')
        $(this).closest('td').find('.inin').html(keyword.key)
        $(this).closest('td').find('[name=product]').val(keyword.id)
        $(this).closest('td').find('.selectedOnlyOne').show()

    })


    //物料搜索补全
    $(".material").bsSuggest({
        url: "{:url('select/materialjson')}",
        effectiveFieldsAlias: {title: "名称"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onDataRequestSuccess', function (e, result) {
        $(this).closest('tr').data('rs',JSON.stringify(result.value))
        console.log('onDataRequestSuccess: ', result);
    }).on('onSetSelectValue', function (e, keyword, data) {
        console.log(keyword,'wl')
        $(this).closest('.input-group').hide()
        $(this).val('')
        $(this).closest('td').find('.inin').html(keyword.key)
        $(this).closest('td').find('[name=product]').val(keyword.id)
        $(this).closest('td').find('.selectedOnlyOne').show()

        console.log('rwerwer')

        var rs = $(this).closest('tr').data('rs')
        rs = JSON.parse(rs)
        for(var i=0;i<rs.length;i++){
            if(rs[i].id==keyword.id){
                $(this).closest('tr').find('.unit').html(rs[i].unit)
                $(this).closest('tr').find('.price').html(rs[i].factory)
            }
        }
    })


    //产品详情
    function showTable(obj,su){
        obj.parent('label').siblings('label').removeClass('active')
        obj.parent('label').addClass('active');
        for (var io =0;io<5;io++){
            $("#proTable"+io).hide();

        }
        $("#proTable"+su).show();
        if(su==4){
            $("#proText").text("注：如选择单品类，则各单品费用将会平摊。如不希望平摊，请填写多次明细。");
        }else {
            $("#proText").text("注：产品费用占比加起来必须等于100%,如果不填费用占比则平摊");
        }

    }
    //品牌
    function c(id) {
        entranceX('proTableInput0'+id,
            "{:url('BiHaiChaoSheng/getCp',['type'=>2,'style'=>1])}",
            '{:url("BiHaiChaoSheng/selectList",["url"=>"getCp","where"=>"type_1__style_1"])}?str=proTableInput0'+id,
            '',
            '');
    }
    uploadTr(changpingxianqin1,'#Cpxq0','',c);
    function addHang3(){
        uploadTr(changpingxianqin1,'#Cpxq0','',c);
    }
    //品类
    function d(id) {
        entranceX('proTableInput1'+id,
            "{:url('BiHaiChaoSheng/getCp',['type'=>2,'style'=>2])}",
            '{:url("BiHaiChaoSheng/selectList",["url"=>"getCp","where"=>"type_1__style_2"])}?str=proTableInput1'+id,
            '',
            '');
    }
    uploadTr(changpingxianqin2,'#Cpxq1','',d);
    function addHang4(){
        uploadTr(changpingxianqin2,'#Cpxq1','',d);
    }
    //系列
    function e(id) {
        entranceX('proTableInput2'+id,
            "{:url('BiHaiChaoSheng/getCp',['type'=>2,'style'=>3])}",
            '{:url("BiHaiChaoSheng/selectList",["url"=>"getCp","where"=>"type_1__style_3"])}?str=proTableInput2'+id,
            '',
            '');
    }
    uploadTr(changpingxianqin3,'#Cpxq2','',e);
    function addHang5(){
        uploadTr(changpingxianqin3,'#Cpxq2','',e);
    }
    //Sku
    function f(id) {
        entranceX('proTableInput3'+id,
            "{:url('BiHaiChaoSheng/getCp',['type'=>2,'style'=>4])}",
            '{:url("BiHaiChaoSheng/selectList",["url"=>"getCp","where"=>"type_1__style_4"])}?str=proTableInput3'+id,
            '',
            '');
    }
    uploadTr(changpingxianqin4,'#Cpxq3','',f);
    function addHang6(){
        uploadTr(changpingxianqin4,'#Cpxq3','',f);
    }
    //单品
    function g(id) {
        entranceX('proTableInput4'+id,
            "{:url('BiHaiChaoSheng/getCp',['type'=>2,'style'=>5])}",
            '{:url("BiHaiChaoSheng/selectList",["url"=>"getCp","where"=>"type_1__style_5"])}?str=proTableInput4'+id,
            '',
            '');
    }
    /*//单品 随货折扣类
    function g2(id) {
        entranceX('proTableInput4'+id,
            "{:url('BiHaiChaoSheng/getCp',['type'=>2,'style'=>5,'jxs'=>$jxsid])}",
            '{:url("BiHaiChaoSheng/selectList",["url"=>"getCp","where"=>"type_1__style_5__jxs_$jxsid"])}?str=proTableInput4'+id,
            '',
            '');
    }*/

    //单品 随货折扣类
    function g2(id) {
        entranceX4('proTableInput4'+id,
            "{:url('BiHaiChaoSheng/getCp',['type'=>2,'style'=>5,'jxs'=>$jxsid])}",
            '{:url("BiHaiChaoSheng/selectList",["url"=>"getCp","where"=>"type_1__style_5__jxs_$jxsid","type"=>2])}?str=proTableInput4'+id,
            '',
            '',2);
    }
    //单品 随货折扣类
    function g3(id) {
        entranceX4('proTableInput4'+id,
            "{:url('BiHaiChaoSheng/getCp',['type'=>2,'style'=>5,'jxs'=>$jxsid])}",
            '{:url("BiHaiChaoSheng/selectList",["url"=>"getCp","where"=>"type_1__style_5__jxs_$jxsid"])}?str=proTableInput4'+id,
            '',
            '',7);
    }

    //单品 特价补差类
    function g4(id) {
        entranceX4('proTableInput4'+id,
            "{:url('BiHaiChaoSheng/getCp',['type'=>2,'style'=>5,'jxs'=>$jxsid])}",
            '{:url("BiHaiChaoSheng/selectList",["url"=>"getCp","where"=>"type_1__style_5__jxs_$jxsid"])}?str=proTableInput4'+id,
            '',
            '',4);
    }

    uploadTr(changpingxianqin5,'#Cpxq4','',g);
    function addHang7(){
        uploadTr(changpingxianqin5,'#Cpxq4','',g);
    }

    function addHang72(){  //随货折扣类
        //uploadTr(changpingxianqin5,'#Cpxq42','',g);
        uploadTr(changpingxianqin6,'#Cpxq42','',g2);
    }
    function addHang73(){  //产品进场类
        uploadTr(changpingxianqin7,'#Cpxq43','',g3);
    }
    function addHang74(){  //特价补差类
        uploadTr(changpingxianqin8,'#Cpxq44','',g4);
    }

    function fRmbchange() {
        var yjall=0;
        $(".fRmb").each(function(){
            var fRmb =$(this).val();
            yjall=Number(yjall)+Number(fRmb);
            //yjall=yjall + fRmb;
        })

        $("#sqfy").text(yjall);
    }

    function Saleschange() {

        var noS =$("#noSales").val();
        var yesS =$("#yesSales").val();
        if(noS!='' && yesS!=''){
            var addS = Number(yesS)-Number(noS);
            $("#addSales").text(addS);
        }
        var sqfy =$("#sqfy").text();
        if(sqfy!='' && yesS!=''){
            var fl = 100*Number(sqfy)/Number(yesS);
            $("#yjfyls").val(fl);
            fl=fl+'%';
            $("#yjfyl").text(fl);
            //
        }

    }


    /*$('.fRmb').on('change',function () {
        console.log('aa');
        var id = $(this).val()
        console.log(id);
        console.log('bb');
        //$('#jxs').load('{:url("getjxses")}?id='+id)
    })*/


    //选择按钮
    $('#is_shejixiaoliang').AddRadioX(
        [
            {
                title:'涉及销量',
                name:'is_shejixiaoliang',
                className:'shengji',
                //isTrue:false,
                isTrue:true,
                value:1,
                fun:function (obj) {
                    $(obj).click(function(){
                        $(this).parent('label').siblings('label').removeClass('active')
                        $(this).parent('label').addClass('active');
                        $("#sallycTable tbody tr td").find('input').attr('disabled',false);
                        $("#sallycTable tbody tr td").find('select').attr('disabled',false);
                    });
                }
            },
            {
                title:'不涉及销量',
                name:'is_shejixiaoliang',
                className:'busheji',
                //isTrue:true,
                isTrue:false,
                value:0,
                fun:function (obj) {
                    $(obj).click(function(){
                        $(this).parent('label').siblings('label').removeClass('active')
                        $(this).parent('label').addClass('active');
                        $("#sallycTable tbody tr td").find('input').attr('disabled',true);
                        $("#sallycTable tbody tr td").find('select').attr('disabled',true);
                    })

                }
            }

        ]
    );
    //AddRadioX
    $('#is_kehuxiangqing').AddRadioX(   //$('#is_kehuxiangqing').AddRadioX(
        [
            {
                title:'经销商',
                name:'is_kehuxiangqing',
                className:'khjinxiaoshnag',
                isTrue:false,
                value:1,
                fun:function (obj) {
                    $(obj).click(function(){
                        $(this).parent('label').siblings('label').removeClass('active')
                        $(this).parent('label').addClass('active')
                        $("#angencyTable").show();
                        $("#sysTable").hide();
                        $("#netTable").hide();
                        $(".netlist").remove();
                        $("#JinXiaoShangZhu").empty();
                        $("#khxqtype").val('1');
                    });
                }
            },
            {
                title:'系统',
                name:'is_kehuxiangqing',
                className:'khxitong',
                isTrue:true,
                value:0,
                fun:function (obj) {
                    $(obj).click(function(){
                        $(this).parent('label').siblings('label').removeClass('active');
                        $(this).parent('label').addClass('active');
                        $("#angencyTable").hide();
                        $("#sysTable").show();
                        $("#netTable").hide();
                        $(".netlist").remove();
                        addHang2();
                        $("#khxqtype").val('2');
                    })
                }
            },
            {
                title:'网点',
                name:'is_kehuxiangqing',
                className:'khwangdian',
                isTrue:false,
                value:0,
                fun:function (obj) {
                    $(obj).click(function(){
                        $(this).parent('label').siblings('label').removeClass('active')
                        $(this).parent('label').addClass('active')
                        $("#angencyTable").hide();
                        $("#sysTable").hide();
                        $("#netTable").show();
                        $("#JinXiaoShangZhu").empty();
                        $("#khxqtype").val('3');
                    })

                }
            }

        ]
    );
    $('#is_changpingxiangqin').AddRadioX(
        [
            {
                title:'品牌',
                name:'is_cpxq',
                className:'cpxqpp',
                /*isTrue:true,*/
                isTrue:false,
                value:1,
                fun:function (obj) {
                    $(obj).click(function(){
                        showTable($(this),0);
                        $("#Cpxq0").empty();
                        $("#Cpxq1").empty();
                        $("#Cpxq2").empty();
                        $("#Cpxq3").empty();
                        $("#Cpxq4").empty();
                        addHang3();
                        $("#cpxqtype").val('1');

                    });
                }
            },
            {
                title:'品类',
                name:'is_cpxq',
                className:'cpxqpl',
                isTrue:true,
                /*isTrue:false,*/
                value:0,
                fun:function (obj) {
                    $(obj).click(function(){
                        showTable($(this),1);
                        $("#Cpxq0").empty();
                        $("#Cpxq1").empty();
                        $("#Cpxq2").empty();
                        $("#Cpxq3").empty();
                        $("#Cpxq4").empty();
                        addHang4();
                        $("#cpxqtype").val('2');
                    })

                }
            },
            {
                title:'系列',
                name:'is_cpxq',
                className:'cpxqxl',
                isTrue:false,
                value:0,
                fun:function (obj) {
                    $(obj).click(function(){
                        showTable($(this),2);
                        $("#Cpxq0").empty();
                        $("#Cpxq1").empty();
                        $("#Cpxq2").empty();
                        $("#Cpxq3").empty();
                        $("#Cpxq4").empty();
                        addHang5();
                        $("#cpxqtype").val('3');
                    })

                }
            },
            {
                title:'SKU',
                name:'is_cpxq',
                className:'cpxqsku',
                isTrue:false,
                value:0,
                fun:function (obj) {
                    $(obj).click(function(){
                        showTable($(this),3);
                        $("#Cpxq0").empty();
                        $("#Cpxq1").empty();
                        $("#Cpxq2").empty();
                        $("#Cpxq3").empty();
                        $("#Cpxq4").empty();
                        addHang6();
                        $("#cpxqtype").val('4');
                    })

                }
            },
            {
                title:'单品',
                name:'is_cpxq',
                className:'cpxqdp',
                isTrue:false,
                value:0,
                fun:function (obj) {
                    $(obj).click(function(){
                        showTable($(this),4);
                        $("#Cpxq0").empty();
                        $("#Cpxq1").empty();
                        $("#Cpxq2").empty();
                        $("#Cpxq3").empty();
                        $("#Cpxq4").empty();
                        addHang7();
                        $("#cpxqtype").val('5');
                    })

                }
            }

        ]
    );


    //删除费用科目项
    $('body').on('click','.del_fi_item',function () {
        $(this).closest('tr').remove()
    })
    //删除
    $('body').on('click','.btn-bitbucket',function () {
        $(this).closest('tr').remove()
        checkfee()
    })

    function nowprice_change5(idnum){

        var id='nowprice'+idnum;
        console.log(id,'id')
        var nowprice = $('#'+id).val();
        var zkid = id.replace("nowprice", "dealerZheJiaLv"); //折扣id
        var yjid = id.replace("nowprice", "oldprice"); //原价id
        var oldprice = $('#'+yjid).val();
        console.log(oldprice,'oldprice')
        console.log(nowprice,'nowprice')
        if(nowprice>=0){
            var zjl =parseFloat(100-(100*nowprice/oldprice).toFixed(2));
            $('#'+zkid).val(zjl);
            console.log('1')
            $('#'+id).val();
        }else {
            $('#'+id).val(oldprice);
            $('#'+zkid).val('0');
        }
    }

    function nowprice_change(idnum){

        var id='nowprice'+idnum;
        console.log(id,'id')
        var nowprice = $('#'+id).val();
        var zkid = id.replace("nowprice", "dealerZheJiaLv"); //折扣id
        var yjid = id.replace("nowprice", "oldprice"); //原价id
        var oldprice = $('#'+yjid).val();
        console.log(oldprice,'oldprice')
        console.log(nowprice,'nowprice')

        var wd=id.replace("nowprice", "nowprice2"); //网点现供价id
        var wdxgj = $('#'+wd).val();  //网点现供价

        if(nowprice>=0){
            var zjl =parseFloat(100-(100*nowprice/oldprice).toFixed(2));//折价率

            var sj='';//顺加
            var dk=''; //倒扣
            if(nowprice>0){
                //sj=100*(wdxgj-nowprice)/nowprice;
                sj=parseFloat(100*(wdxgj-nowprice)/nowprice).toFixed(2);
            }else {
                sj='';
            }
            if(wdxgj>0){
                //dk=100*(nowprice-wdxgj)/wdxgj;

                dk=parseFloat(100*(nowprice-wdxgj)/wdxgj).toFixed(2);
            }else {
                dk='';
            }

            console.log(sj,'sj')
            console.log(dk,'dk')
            /*var sjv=sj.toFixed(2);
            var dkv=dk.toFixed(2);*/

            var str='                            顺加'+sj+'% 倒扣'+dk+'%\n' +
                '<a class="hover" href="#">\n' +
                '                                <span>帮助</span>\n' +
                '                                <div class="ex" style="width: 400px;height: 100px;">经销商的顺加毛利率 =（网点现供价 - 经销商现供价）/ 经销商现供价\n' +
                '                                    <br>\n' +
                '                                    经销商的倒扣毛利率 = （网点现供价 - 经销商现供价）/ 网点现供价</div>\n' +
                '                            </a>';


            var  jj=$('#'+id).parent().next().next().html();//这个是对的
            $('#'+id).parent().next().next().next().next().html(str);

            $('#'+zkid).val(zjl);
            $('#'+id).val();
        }else {
            $('#'+id).val(oldprice);
            $('#'+zkid).val('0');
        }
    }
    function nowprice_change2(idnum){

        var id='nowprice2'+idnum;
        var nowprice = $('#'+id).val();
        var zkid='dealerZheJiaLv2'+idnum;
        var yjid='oldprice2'+idnum;
        var oldprice = $('#'+yjid).val();
        if(nowprice>=0){
            var zjl =parseFloat(100-(100*nowprice/oldprice).toFixed(2));
            $('#'+zkid).val(zjl);
            $('#'+id).val();
        }else {
            $('#'+id).val(oldprice);
            $('#'+zkid).val('0');
        }
    }

    function ZheJiaLv_change(idnum){
        console.log(idnum,'idnum')
        var id='dealerZheJiaLv'+idnum;         //折价率id
        console.log(id,'id')
        var ZheJiaLv = $('#'+id).val(); //折价率
        var xjid = id.replace("dealerZheJiaLv", "nowprice"); //现价id
        var yjid = id.replace("dealerZheJiaLv", "oldprice"); //原价id
        var oldprice = $('#'+yjid).val();  //原价

        var wd=id.replace("dealerZheJiaLv", "nowprice2"); //网点现供价id
        var wdxgj = $('#'+wd).val();  //网点现供价

        console.log(ZheJiaLv,'ZheJiaLv')
        if(ZheJiaLv>=0){
            var xj =oldprice*(100-ZheJiaLv)/100; //现价
            var sj='';
            var dk='';
            if(xj>0){
                //sj=100*(wdxgj-xj)/xj;

                sj=parseFloat(100*(wdxgj-xj)/xj).toFixed(2);
            }else {
                sj='';
            }
            if(wdxgj>0){
                //dk=100*(xj-wdxgj)/wdxgj;

                dk=parseFloat(100*(xj-wdxgj)/wdxgj).toFixed(2);
            }else {
                dk='';
            }

            $('#'+xjid).val(xj);

            var str='                            顺加'+sj+'% 倒扣'+dk+'%\n' +
                '<a class="hover" href="#">\n' +
                '                                <span>帮助</span>\n' +
                '                                <div class="ex" style="width: 400px;height: 100px;">经销商的顺加毛利率 =（网点现供价 - 经销商现供价）/ 经销商现供价\n' +
                '                                    <br>\n' +
                '                                    经销商的倒扣毛利率 = （网点现供价 - 经销商现供价）/ 网点现供价</div>\n' +
                '                            </a>';


            var  jj=$('#'+id).parent().next().next().html();//这个是对的
            $('#'+id).parent().next().next().html(str);
        }else {
            $('#'+xjid).val(oldprice);
            $('#'+id).val('0');
        }
    }

    function ZheJiaLv_change2(idnum){

        var id='dealerZheJiaLv2'+idnum;         //折价率id
        console.log(id,'id')
        var ZheJiaLv = $('#'+id).val(); //折价率
        var xjid = id.replace("dealerZheJiaLv2", "nowprice2"); //现价id
        var yjid = id.replace("dealerZheJiaLv2", "oldprice2"); //原价id
        var oldprice = $('#'+yjid).val();  //原价
        console.log(ZheJiaLv,'ZheJiaLv')
        if(ZheJiaLv>=0){
            var xj =oldprice*(100-ZheJiaLv)/100;
            $('#'+xjid).val(xj);

        }else {
            $('#'+xjid).val(oldprice);
            $('#'+id).val('0');
        }
    }

    $(function () {
        //点击物料样品单选
        $('body').on('click','.wy',function () {
            var val=$(this).val();
            var kk=$(this).parents('td');
            kk.closest('td').find('.inin').html('')
            kk.closest('td').find('[name=product]').val('')
            kk.closest('td').find('.selectedOnlyOne').hide()
            kk.find('.inin').html('')
            kk.find('[name=product]').val('')
            kk.find('.selectedOnlyOne').hide()
            var numid =$(this).attr("data-id")
            var wyval=$(this).val();
            if($(this).val()==1){  //为什么进不去这里
                $("#ypwlType"+numid).val('0');
                var class1 = kk.find('#wlName'+numid).attr('class');
                var ids='#wlName'+numid;
                kk.find('#wlName'+numid).show()
                kk.find('#wlName2'+numid).hide()
            }else{
                $("#ypwlType"+numid).val('1');
                kk.find('#wlName'+numid).hide()
                kk.find('#wlName2'+numid).show()
                var ids='#wlName2'+numid;
                var class1 = kk.find('#wlName2'+numid).attr('class');
                /*kk.find('#select2wlName'+numid).hide()
                kk.find('#select2wlName2'+numid).show()*/
            }
        })
    })

    $(document).ready(function () {
        //样品搜索补全
        $(".sample").bsSuggest({
            url: "{:url('select/samplejson')}",
            effectiveFieldsAlias: {title: "名称"},
            ignorecase: true,
            showHeader: true,
            showBtn: false,     //不显示下拉按钮
            delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
            idField: "id",
            keyField: "title",
            clearable: true
        }).on('onSetSelectValue', function (e, keyword, data) {
            console.log('yp')
            $(this).closest('.input-group').hide()
            $(this).val('')
            $(this).closest('td').find('.inin').html(keyword.key)
            $(this).closest('td').find('[name=product]').val(keyword.id)
            $(this).closest('td').find('.selectedOnlyOne').show()

        })


        //物料搜索补全
        $(".material").bsSuggest({
            url: "{:url('select/materialjson')}",
            effectiveFieldsAlias: {title: "名称"},
            ignorecase: true,
            showHeader: true,
            showBtn: false,     //不显示下拉按钮
            delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
            idField: "id",
            keyField: "title",
            clearable: true
        }).on('onDataRequestSuccess', function (e, result) {
            $(this).closest('tr').data('rs',JSON.stringify(result.value))
            console.log('onDataRequestSuccess: ', result);
        }).on('onSetSelectValue', function (e, keyword, data) {
            console.log('wl')
            $(this).closest('.input-group').hide()
            $(this).val('')
            $(this).closest('td').find('.inin').html(keyword.key)
            $(this).closest('td').find('[name=product]').val(keyword.id)
            $(this).closest('td').find('.selectedOnlyOne').show()

            var rs = $(this).closest('tr').data('rs')
            rs = JSON.parse(rs)
            for(var i=0;i<rs.length;i++){
                if(rs[i].id==keyword.id){
                    $(this).closest('tr').find('.unit').html(rs[i].unit)
                    $(this).closest('tr').find('.price').html(rs[i].factory)
                }
            }
        })

    })

    function num_to(num){

        var xtnumid = 'JinXiaoShangNum'+num;
        var rs = $('#'+xtnumid).attr('rs');
        var xtnum = $('#'+xtnumid).val();
        if(rs!=''){
            if(xtnum>rs){
                var xtnameid = 'selectJinXiaoShang'+num;
                var xtname = $('#'+xtnameid).find('.inin').html();

                alert(xtname+'网点数最多为'+rs);
                var xtnum = $('#'+xtnumid).val(rs);
            }else if(!(xtnum>0)){
                var xtnum = $('#'+xtnumid).val(0);
            }

        }


    }



</script>
</body>

</html>